<html>
<head><meta charset="utf-8"><title>Look up the Res for the DefId of a primitive impl? · t-compiler/help · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/index.html">t-compiler/help</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Look.20up.20the.20Res.20for.20the.20DefId.20of.20a.20primitive.20impl.3F.html">Look up the Res for the DefId of a primitive impl?</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="211557902"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Look%20up%20the%20Res%20for%20the%20DefId%20of%20a%20primitive%20impl%3F/near/211557902" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Look.20up.20the.20Res.20for.20the.20DefId.20of.20a.20primitive.20impl.3F.html#211557902">(Sep 28 2020 at 22:20)</a>:</h4>
<p>I have the <code>DefId</code> for the following impl:</p>
<div class="codehilite" data-code-language="Rust"><pre><span></span><code><span class="cp">#![no_core]</span><span class="w"></span>

<span class="cp">#[lang = </span><span class="s">"usize"</span><span class="cp">]</span><span class="w"></span>
<span class="k">impl</span><span class="w"> </span><span class="kt">usize</span><span class="w"> </span><span class="p">{</span><span class="w"></span>
<span class="w">    </span><span class="sd">/// Some docs</span>
<span class="w">    </span><span class="k">pub</span><span class="w"> </span><span class="k">fn</span> <span class="nf">f</span><span class="p">()</span><span class="w"> </span><span class="p">{}</span><span class="w"></span>
<span class="p">}</span><span class="w"></span>
</code></pre></div>

<p>It looks like <code>DefId(0:1 ~ intra_link_prim_self[8787]::{impl#0})</code>. Is there a way to get the corresponding <code>Res::PrimTy</code> for it? I found <a href="https://doc.rust-lang.org/nightly/nightly-rustc/rustc_hir/lang_items/struct.LanguageItems.html?search=#method.items"><code>LanguageItems::items</code></a> that I could use to look up the <code>LangItem</code> for it, but I don't see a way to go from that to a <code>Res</code>.</p>
<p>context: <a href="https://github.com/rust-lang/rust/pull/76467">https://github.com/rust-lang/rust/pull/76467</a></p>



<a name="211584545"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Look%20up%20the%20Res%20for%20the%20DefId%20of%20a%20primitive%20impl%3F/near/211584545" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Look.20up.20the.20Res.20for.20the.20DefId.20of.20a.20primitive.20impl.3F.html#211584545">(Sep 29 2020 at 06:20)</a>:</h4>
<p>hmm, does <code>tcx.impl_trait_ref.map(false, |t| t.self_ty().is_primitive_ty())</code> work for you here?</p>



<a name="211615580"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Look%20up%20the%20Res%20for%20the%20DefId%20of%20a%20primitive%20impl%3F/near/211615580" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Look.20up.20the.20Res.20for.20the.20DefId.20of.20a.20primitive.20impl.3F.html#211615580">(Sep 29 2020 at 12:49)</a>:</h4>
<p>Hmm, the Ty gets me halfway there but rustdoc wants a PrimTy</p>



<a name="211615599"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Look%20up%20the%20Res%20for%20the%20DefId%20of%20a%20primitive%20impl%3F/near/211615599" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Look.20up.20the.20Res.20for.20the.20DefId.20of.20a.20primitive.20impl.3F.html#211615599">(Sep 29 2020 at 12:49)</a>:</h4>
<p>(deleted)</p>



<a name="211615600"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Look%20up%20the%20Res%20for%20the%20DefId%20of%20a%20primitive%20impl%3F/near/211615600" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Joshua Nelson <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Look.20up.20the.20Res.20for.20the.20DefId.20of.20a.20primitive.20impl.3F.html#211615600">(Sep 29 2020 at 12:49)</a>:</h4>
<p>Maybe I could just write out the match and add it to an <code>impl Ty</code>?</p>



<a name="211671922"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/182449-t-compiler/help/topic/Look%20up%20the%20Res%20for%20the%20DefId%20of%20a%20primitive%20impl%3F/near/211671922" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> lcnr <a href="https://rust-lang.github.io/zulip_archive/stream/182449-t-compiler/help/topic/Look.20up.20the.20Res.20for.20the.20DefId.20of.20a.20primitive.20impl.3F.html#211671922">(Sep 29 2020 at 19:26)</a>:</h4>
<p>yeah, adding a method to <code>TyS</code> probably makes sense here <span aria-label="thumbs up" class="emoji emoji-1f44d" role="img" title="thumbs up">:thumbs_up:</span></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>